/**
 * Copyright (C) 2011, mordredd666 [_at_] gmail.com
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package de.mordred.gui.lernen;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import de.mordred.Main;
import de.mordred.gui.FixedPanel;
import de.mordred.gui.TopLeiste;
import de.mordred.gui.VerticalFlowLayout;

public class FachSelection extends FixedPanel
{

	private static final long serialVersionUID = -5815149241723759456L;

	public FachSelection(ArrayList<String> fächer)
	{

		this.setLayout(new BorderLayout());

		this.add(new TopLeiste(getTitel()), BorderLayout.NORTH);

		JPanel center = new JPanel(new VerticalFlowLayout());
		this.add(center, BorderLayout.CENTER);

		for (String s : fächer)
		{

			JPanel selection = new JPanel();
			selection.setLayout(new BorderLayout());
			selection.setBorder(BorderFactory.createEtchedBorder(Color.blue, Color.black));
			JLabel name = new JLabel("        "+s);
			name.setSize(100, 50);
			name.setMaximumSize(new Dimension(100,50));
			name.setMinimumSize(new Dimension(100,50));
			name.setPreferredSize(new Dimension(100,50));

			selection.add(name, BorderLayout.CENTER);
			selection.add(new JLabel(">"), BorderLayout.EAST);


			selection.addMouseListener(getAdapter(s));
			name.addMouseListener(getAdapter(s));

			center.add(selection);
		}

	}

	private MouseAdapter getAdapter(final String fach)
	{
		return new MouseAdapter()
		{
			@Override
			public void mouseClicked(MouseEvent e)
			{
				ArrayList<String> themen = Main.getThemenFürFach(fach);
				Main.setNextPanel(new ThemaSelection(fach, themen));
			}
		};
	}

	@Override
	public String getTitel()
	{
		return "Fächer";
	}

}
